#include "StdAfx.h"
#include "FilerFrogSettings.h"

FilerFrogSettings::FilerFrogSettings()
{
}

FilerFrogSettings::~FilerFrogSettings()
{
}


void FilerFrogSettings::SetFavoritesSettings(bool useDefault)
{
	HKEY hkey;
	DWORD dwDisposition; 
	DWORD dwType, dwSize;

	long lResult = RegCreateKeyEx(
						HKEY_CURRENT_USER,
						TEXT("Software\\FilerFrog"),
						0,
						NULL,
						REG_OPTION_NON_VOLATILE,
						KEY_ALL_ACCESS,
						NULL,
						&hkey,
						&dwDisposition);

	bool szValue = useDefault;

	if (lResult == ERROR_SUCCESS)
	{		
		dwType = REG_BINARY;		
		dwSize = sizeof(szValue);
		lResult = RegSetValueEx(hkey, L"FavoritesSettings", 0, dwType, (PBYTE)&szValue, dwSize);
		RegCloseKey(hkey);
	}
}

bool FilerFrogSettings::GetFavoritesSettings()
{
	HKEY hkey;
	DWORD dwType, dwSize;

	long lResult = RegOpenKeyEx(
						HKEY_CURRENT_USER,
						TEXT("Software\\FilerFrog"),
						0,
						KEY_QUERY_VALUE,						
						&hkey);

	bool szValue = true;

	if (lResult == ERROR_SUCCESS)
	{		
		dwType = REG_BINARY;					
		dwSize = sizeof(szValue);
		RegQueryValueEx(hkey, L"FavoritesSettings" , 0, &dwType, (LPBYTE)&szValue, &dwSize);
		RegCloseKey(hkey);
	}

	return szValue;
}

void FilerFrogSettings::SetCheckForUpdatesSettings(int daysInterval)
{
	CRegKey key;

	long nError = key.Open(HKEY_CURRENT_USER, L"Software\\FilerFrog", KEY_WRITE);

	if (nError == ERROR_SUCCESS)
	{
		ULONG nBytes = sizeof(int);
		key.SetBinaryValue(L"AutomaticUpdatesInterval", &daysInterval, nBytes);
	}
}

int FilerFrogSettings::GetCheckForUpdatesSettings()
{
	CRegKey key;
	int retVal = 7;

	long nError = key.Open(HKEY_CURRENT_USER, L"Software\\FilerFrog", KEY_READ);

	if (nError == ERROR_SUCCESS)
	{
		ULONG nBytes = sizeof(int);

		key.QueryBinaryValue(L"AutomaticUpdatesInterval", &retVal, &nBytes);

		if (nBytes != sizeof(int))
		{
			retVal = 7;
		}
	}

	return retVal;
}
